package cn.edu.zucc.controller;

import cn.edu.zucc.dao.eduexp.EduExpMapperExamp;
import cn.edu.zucc.entity.Stu;
import cn.edu.zucc.service.StuService;
import cn.edu.zucc.util.ReturnT;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


/**
 * @description stu
 * @author zhengkai.blog.csdn.net
 * @date 2022-04-13
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/stu")
public class StuControllerMybatis {

    @Resource
    private StuService stuService;

    /**
     * id 存在就更新 不然插入
     * @param stu
     * @return
     */
    @PostMapping("/save")
    public Object save(@RequestBody  Stu stu){
        return stuService.save(stu);
    }

    /**
     * 新增
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/insert")
    public Object insert(Stu stu){
        return stuService.insert(stu);
    }

    /**
     * 刪除
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/delete")
    public Object delete(int id){
        return stuService.delete(id);
    }

    /**
     * 更新
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/update")
    public Object update(Stu stu){
        return stuService.update(stu);
    }

    /**
     * 查询 根据主键 id 查询
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/load")
    public Object load(int id){
        return stuService.load(id);
    }

//    @Resource
//    EduExpMapperExamp eduExpMapper;
//    @PostMapping("/load")
//    public Object loadd(int id){
//        return stuService.load(id);
//    }

    /**
     * 查询 分页查询
     * @author zhengkai.blog.csdn.net
     * @date 2022/04/13
     **/
    @PostMapping("/list")
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int pageNumber,
                                        @RequestParam(required = false, defaultValue = "10") int pageSize) {
//        ReturnT
        return stuService.pageList(pageNumber, pageSize);
        //Map<String, Object> pageList = stuService.pageList(pageNumber, pageSize);
//return ReturnT.success(pageList);
    }
}
